using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace Snow
{
    public partial class FormOption : Form
    {
        public event EventHandler WindChanged;
        public event EventHandler OpacityChanged;
        public event EventHandler NumberChanged;
        RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        public FormOption()
        {
            InitializeComponent();
        }

        public int Wind
        {
            get { return trackBar1.Value; }
            set
            {
                if (trackBar1.Value != value)
                    trackBar1.Value = value;
                if (WindChanged != null)
                    WindChanged(null, null);
                lblWind.Text = value.ToString();
            }
        }

        public double OpacityValue
        {
            get { return (double)trackBar2.Value / 100; }
            set
            {
                trackBar2.Value = (int)value * 100;
                lblOpacity.Text = trackBar2.Value.ToString();
            }
        }

        public int NumberSnow
        {
            get { return (int)numericUpDown1.Value; }
            set { numericUpDown1.Value = value; }
        }
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            this.Wind = trackBar1.Value;
            lblWind.Text = this.Wind.ToString();
        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            lblOpacity.Text = trackBar2.Value.ToString();
            if (OpacityChanged != null)
                OpacityChanged(sender, e);
        }

        private void BT_Ok_Click(object sender, EventArgs e)
        {
            if (NumberChanged != null)
                NumberChanged(numericUpDown1, null);
        }

        private void BT_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            SetStartup(checkBox1.Checked);
        }

        private void SetStartup(bool bStart)
        {
            Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            if (bStart)
                rk.SetValue("MVT-Snow", Application.ExecutablePath.ToString());
            else
                rk.DeleteValue("MVT-Snow", false);
        }

        private void FormOption_Load(object sender, EventArgs e)
        {
            if(rk.GetValue("MVT-Snow")==null)
            {
                checkBox1.Checked = false;
            }
            else
            {
                if (rk.GetValue("MVT-Snow").ToString() == Application.ExecutablePath.ToString())
                {
                    checkBox1.Checked = true;
                }
                else
                {
                    checkBox1.Checked = false;
                }
            }
        }
    }
}